package net.lgpage.util;

import java.util.List;
import java.util.Timer;
import java.util.TimerTask;

import android.os.AsyncTask;

public class Cleaner {
	
	public static void cleanAll(Object ...objs){
		for(int i = 0;i<objs.length;i++){
			Object obj = objs[i];
			if(obj instanceof AsyncTask){
				AsyncTask task = (AsyncTask) obj;
				task.cancel(true);
			}else if(obj instanceof Timer){
				Timer timer = (Timer) obj;
				timer.cancel();
			}else if(obj instanceof TimerTask){
				TimerTask task = (TimerTask) obj;
				task.cancel();
			}else if(obj instanceof List){
				List list = (List) obj;
				list.clear();
			}
		}
	}

	public static void cleanTask(AsyncTask ...tasks){
		for(int i = 0;i<tasks.length;i++){
			if(tasks[i]!=null){
				tasks[i].cancel(true);
				tasks[i] = null;
			}
		}
		tasks = null;
	}
	
	public static void cleanList(List ...lists){
		for(int i = 0;i<lists.length;i++){
			if(lists[i]!=null){
				lists[i].clear();
				lists[i] = null;
			}
		}
		lists = null;
	}
	public static void cleanTimer(Timer ...lists){
		for(int i = 0;i<lists.length;i++){
			if(lists[i]!=null){
				lists[i].cancel();
				lists[i] = null;
			}
		}
		lists = null;
	}
}
